/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-03-27
 * Time: 18:31
 */
public class test_4 {
    public static int rob(int[] nums) {
        int n=nums.length;
        return Math.max(nums[0] + rob1(nums, 2, n - 2), rob1(nums, 1, n - 1));
    }
    public static int rob1(int[] num,int left,int right){
        if(left > right) return 0;
        int n=num.length;
        int[] dp=new int[n];
        int[] f=new  int[n];
        int[] g=new int[n];
        f[left]=num[left];
        for (int i = left+1; i <= right; i++) {
            f[i]=g[i-1]+num[i];
            g[i]=Math.max(f[i-1],g[i-1]);
        }
        return Math.max(f[right],g[right]);

    }
    public static void main(String[] args) {

    }
}
